package com.etalk.crm.serviceImpl;

import com.etalk.crm.dao.AdminNewMainMapper;
import com.etalk.crm.pojo.NewMainBean;
import com.etalk.crm.service.AdminNewMainService;
import com.etalk.crm.utils.DateUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;


/**
 * @author Jordan
 */
@Service
public class AdminNewMainServiceImpl implements AdminNewMainService {

    @Resource
    private AdminNewMainMapper adminNewMainMapper;

    /**
     * 处理首页待约中教课学员数据
     * @param revisitId 客户属性id
     * @param page 页码
     * @param size 页记录数
     * @return
     */
    @Override
    public PageInfo<NewMainBean> searchNotBookedClassList(Integer revisitId, Integer sscId, Integer page, Integer size) {

        PageHelper.startPage(page, size);
        List<NewMainBean> list=adminNewMainMapper.selectNotBookedChineseCourseList(revisitId,sscId);
        return new PageInfo<>(list);
    }

    /**
     * 查询未提交检测报告的学员名单
     * @param sscId ssc id
     * @param page 页码
     * @param size 记录数
     * @return
     */
    @Override
    public PageInfo<NewMainBean> searchLtNotFeedbackList(Integer sscId, Integer page, Integer size) {
        PageHelper.startPage(page, size);
        List<NewMainBean> list=adminNewMainMapper.selectLtNotFeedbackList(sscId);
        return new PageInfo<>(list);
    }

    @Override
    public PageInfo<NewMainBean> searchStudentOrderInfo(Integer sscId, Integer ccId, Integer days, Integer page, Integer size) {
        PageHelper.startPage(page, size);
        return new PageInfo<>(adminNewMainMapper.selectStudentOrderInfo(sscId,ccId,days));
    }

    @Override
    public PageInfo<NewMainBean> searchOcOldStudentFollow(Integer sscId, Integer ccId, Integer followDays, Integer page, Integer size) {
        PageHelper.startPage(page, size);
        return new PageInfo<>(adminNewMainMapper.selectOcOldStudentFollow(sscId,ccId,followDays));
    }

    @Override
    public PageInfo<NewMainBean> searchPotentialStudent(Integer ccId, Integer state, Integer page, Integer size) {
        PageHelper.startPage(page, size);
        return new PageInfo<>(adminNewMainMapper.selectPotentialStudent(ccId,state));
    }

    @Override
    public PageInfo<NewMainBean> searchInactiveLessons(Integer sscId, Integer ccId, Integer page, Integer size) {
        PageHelper.startPage(page, size);
        return new PageInfo<>(adminNewMainMapper.selectInactiveLessons(sscId,ccId));
    }

    /**
     *
     * @param sscId ssc id
     * @param ccId cc id
     * @param page 页码
     * @param size 页记录数
     * @return
     */
    @Override
    public PageInfo<NewMainBean> searchAbsenteeismLessonList(Integer sscId, Integer ccId, Integer page, Integer size) {
        PageHelper.startPage(page, size);
        return new PageInfo<>(adminNewMainMapper.selectAbsenteeismLessonList(sscId,ccId));
    }

    /**
     * 提醒列表
     * @param ccId cc id
     * @param searchDate 日期
     * @param page 页码
     * @param size 页记录数
     * @return
     */
    @Override
    public PageInfo<NewMainBean> searchTrackRemindList(List<Integer> ccId, String searchDate, Integer page, Integer size) {
        PageHelper.startPage(page, size);
        List<NewMainBean> list=adminNewMainMapper.selectTrackRemindList(ccId,searchDate);
        if (list!=null && list.size()>0){
            for (NewMainBean newMainBean : list) {
                if (newMainBean.getReleaseTime().getTime() > DateUtil.getCurrentDatetime().getTime()) {
                    newMainBean.setExpired(0);
                } else {
                    newMainBean.setExpired(1);
                }
            }
        }
        return new PageInfo<>(list);
    }
}
